﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Mimoza.ObjectLayer;
using Mimoza.Apps.Console.Commands;

namespace Mimoza.Apps.Console.ViewModel
{
    public abstract class BaseViewModel: INotifyPropertyChanged
    {
        protected Application m_application = null;
        protected List<BaseConsoleCommand> m_ToolBarCommands = new List<BaseConsoleCommand>();
        protected List<BaseConsoleCommand> m_ContextCommands = new List<BaseConsoleCommand>();

        private Object m_context = null;
        private bool m_InFocus;
        private bool m_Visible;

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public event EventHandler<ObjectLayer_ObjectChangedEventArgs> OnObjectChanged;
        protected void RaiseOnObjectChanged(ObjectLayer_ObjectChangedEventArgs e)
        {
            EventHandler<ObjectLayer_ObjectChangedEventArgs> handler = OnObjectChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }

        public virtual void Init(Mimoza.Apps.Console.Application application)
        {
            m_application = application;
        }

        public Application Application
        {
            get
            {
                return m_application;
            }
        }
        public virtual Object Context
        {
            get { return m_context; }
            set {  
                if (m_context != value)
                {
                    m_context = value;
                    NotifyPropertyChanged("Context");
                }
            }
        }
        public bool InFocus
        {
            get
            {
                return m_InFocus;
            }
            set
            {
                if (m_InFocus != value)
                {
                    m_InFocus = value;
                    NotifyPropertyChanged("InFocus");
                }
            }
        }
        public bool Visible
        {
            get
            {
                return m_Visible;
            }
            set
            {
                if (m_Visible != value)
                {
                    m_Visible = value;
                    NotifyPropertyChanged("Visible");
                }
            }
        }

        public virtual IEnumerable<BaseConsoleCommand> ToolBarCommands
        {
            get
            {
                return m_ToolBarCommands;
            }
        }
        public virtual IEnumerable<BaseConsoleCommand> ContextCommands
        {
            get
            {
                return m_ContextCommands;
            }
        }
    }
}
